import Store from '../store/index.js'

export default {
    inserted: async(el, { value }) => {
        if (typeof value === 'undefined') {
            console.warn(`使用权限指令，需要绑定值. 示例：v-permission="'collect:management'"`);
            return;
        }
        let permissions = Store.state.main.permission;

        let hasPermission = false;
        permissions.forEach(v => {
            if (v.resourceCode === value) {
                hasPermission = true;
            }
        })
        if (hasPermission) {
            el.className = el.className.replace("_permission-hide", " ");
        } else {
            el.className += " " + "_permission-hide";
        }
    }
}